#include <stdio.h>
#include "main.h"


int main(void)
{
	nvic_vector_table_set(NVIC_VECTTAB_FLASH, 0x2800);
	nvic_priority_group_set(NVIC_PRIGROUP_PRE4_SUB0);
	systimer_init();
	debug_uart_init();
	comm_uart_init();
	i2c_init();
	button_init();
	relay_init();
	led_init();
	system_init();
	printf("Hello Mx 4Key\r\n");
	printf("SoftVersion: %d.%d.%d\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH);
	while(1)
	{
		if(systemTimer.flag5ms)
		{
			systemTimer.flag5ms = 0;
			button_scan();
		}
		if(systemTimer.flag10ms)
		{
			systemTimer.flag10ms = 0;
		}
		if(systemTimer.flag20ms)
		{
			systemTimer.flag20ms = 0;
		}
		if(systemTimer.flag50ms)
		{
			systemTimer.flag50ms = 0;
		}
		if(systemTimer.flag100ms)
		{
			systemTimer.flag100ms = 0;
		}
		if(systemTimer.flag200ms)
		{
			systemTimer.flag200ms = 0;
			system_process();
		}
		if(systemTimer.flag500ms)
		{
			systemTimer.flag500ms = 0;
		}
		if(systemTimer.flag1000ms)
		{
			systemTimer.flag1000ms = 0;
		}
		comm_receiver_process();
	}
}


